home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Mnu / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  2.8 KB  |  118 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef DEFINES_K
  10. #include "Defines.k"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. // ----- Framework Layer -----
  18. #ifndef FWCONTXT_H
  19. #include "FWContxt.h"            // FW_CViewContext
  20. #endif
  21.  
  22. #ifndef FWEVENT_H
  23. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  24. #endif
  25.  
  26. // ----- OS Layer -----
  27. #ifndef FWMENU_H
  28. #include "FWMenu.h"                // FW_CMenuBar, etc.
  29. #endif
  30.  
  31. #ifndef SLMIXOS_H
  32. #include "SLMixOS.h"            // FW_Beep
  33. #endif
  34.  
  35. // ----- Graphic Includes -----
  36. #ifndef FWRECT_H
  37. #include <FWRect.h>                // FW_CRect
  38. #endif
  39.  
  40. #ifndef FWRECSHP_H
  41. #include "FWRecShp.h"            // FW_CRectShape
  42. #endif
  43.  
  44. //========================================================================================
  45. #ifdef FW_BUILD_MAC
  46. #pragma segment Mnu
  47. #endif
  48.  
  49. FW_DEFINE_AUTO(CMnuFrame)
  50.  
  51. //========================================================================================
  52. CMnuFrame::CMnuFrame(Environment* ev, ODFrame* odFrame, 
  53.                         FW_CPresentation* presentation, CMnuPart* mnuPart)
  54.   : FW_CFrame(ev, odFrame, presentation, mnuPart),
  55.     fMnuPart(mnuPart),
  56.     fSoundOn(true)
  57. {
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. CMnuFrame::~CMnuFrame()
  62. {
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. void 
  67. CMnuFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  68. {
  69.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  70.     FW_CRect invalidRect;
  71.     context.GetClipRect(invalidRect);
  72.  
  73.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk); // erase
  74.  
  75.     FW_CRect mnuRect = this->GetBounds(ev);
  76.     FW_CRectShape rectShape(mnuRect, FW_kFill);
  77.     rectShape.GetInk().SetForeColor(FW_kRGBLightGray);
  78.     rectShape.Render(context);
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. FW_Handled 
  83. CMnuFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  84.                                                     FW_Boolean isRoot)    // Override
  85. {
  86.     FW_UNUSED(isRoot);
  87.     if (hasMenuFocus) {
  88.         menuBar->EnableCommand(ev, cItemThreeCommand, true);
  89.         menuBar->EnableAndCheckCommand(ev, cSoundCommand, 
  90.                                                 true,             // enable
  91.                                                 fSoundOn);        // checkmark
  92.     }
  93.     return false;
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. FW_Handled 
  98. CMnuFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  99. {
  100.     FW_Handled menuHandled = true;
  101.     
  102.     switch (theMenuEvent.GetCommandID(ev))
  103.     {
  104.         case cItemThreeCommand:
  105.             if (fSoundOn) FW_Beep();
  106.             break;
  107.  
  108.         case cSoundCommand:
  109.             fSoundOn = !fSoundOn;
  110.             break;
  111.  
  112.         default:
  113.             menuHandled = false;
  114.     }
  115.     return menuHandled;
  116. }
  117.  
  118.